package cn.zhentao.service.impl;

import cn.zhentao.mapper.DeliveryMenMapper;
import cn.zhentao.mapper.DeliveryTasksMapper;
import cn.zhentao.pojo.DeliveryMen;
import cn.zhentao.pojo.DeliveryTasks;
import cn.zhentao.pojo.QueryDeliverMen;
import cn.zhentao.service.IDeliveryMenService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 配送员信息表 服务实现类
 * </p>
 *
 * @author mp
 * @since 2025-06-16
 */
@Service
public class DeliveryMenServiceImpl extends ServiceImpl<DeliveryMenMapper, DeliveryMen> implements IDeliveryMenService {

    @Autowired
    DeliveryMenMapper deliveryMenMapper;

    @Autowired
    DeliveryTasksMapper deliveryTasksMapper;
    @Override
    public Page<DeliveryMen> adminDeliverySouSu(QueryDeliverMen queryDeliverMen) {
        Page<DeliveryMen>page=new Page<>(queryDeliverMen.getCurrent(), queryDeliverMen.getSize());
        QueryWrapper<DeliveryMen>wrapper=new QueryWrapper<>();
        wrapper.like(queryDeliverMen.getName() != null,"name",queryDeliverMen.getName());
        wrapper.like(queryDeliverMen.getPhone() != null,"phone",queryDeliverMen.getPhone());
        wrapper.like(queryDeliverMen.getStatus()!=null,"status",queryDeliverMen.getStatus());
//        wrapper.between("created_at",queryDeliverMen.getStartRegisterTime(),queryDeliverMen.getEndRegisterTime());
        deliveryMenMapper.selectPage(page,wrapper);
        List<DeliveryMen> list = page.getRecords();
        for (DeliveryMen deliveryMen : list) {
            QueryWrapper<DeliveryTasks>deliveryTasksQueryWrapper=new QueryWrapper<>();
            deliveryTasksQueryWrapper.eq("deliveryman_id",deliveryMen.getId());
            Long aLong = deliveryTasksMapper.selectCount(deliveryTasksQueryWrapper);
            deliveryMen.setCount(aLong);

        }
        return page;
    }
}
